package tech.xs.sys.domain.entity;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;

import java.time.LocalDate;
import java.util.regex.Matcher;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import tech.xs.common.framework.domain.constant.DatePattern;
import tech.xs.common.framework.domain.entity.BaseEntity;
import tech.xs.common.sys.domain.enums.SysAccountStatusEnum;
import tech.xs.common.domain.enums.SexEnum;
import tech.xs.common.framework.domain.exception.InvalidParameterException;

import static tech.xs.common.util.pattern.CommonPattern.NUMERIC_LETTER_32;

/**
 * 系统用户
 *
 * @author 沈家文
 * @since 2023/6/21 15:33
 */
@Getter
@Setter
@ToString
@TableName("sys_user")
public class SysUser extends BaseEntity {

    @TableField(insertStrategy = FieldStrategy.NOT_NULL)
    private String userName;

    private String nickName;

    private String phone;

    private String email;

    private String realName;

    /**
     * 身份证号
     */
    private String idNumber;

    private SexEnum sex;

    private SysAccountStatusEnum accountStatus;

    @JsonFormat(pattern = DatePattern.NORM_DATE_PATTERN)
    private LocalDate birthDate;

    private String avatarUrl;

    private Long companyId;

    /**
     * 自我介绍
     */
    private String introduction;

    public static void checkUserName(String userName, String fieldName) {
        Matcher m = NUMERIC_LETTER_32.matcher(userName);
        if (!m.matches()) {
            throw new InvalidParameterException(fieldName, "用户名只能是大小写字母或数字,最多32个字符");
        }
    }


}
